import 'package:flutter/material.dart';
import 'package:vega/constant/constant.dart';
import 'package:vega/page/home_page.dart';
import 'package:vega/page/rank_page.dart';
import 'package:vega/widget/navigation/navigation_bar_item.dart';
import 'package:vega/widget/navigation/navigation_bar_widget.dart';


class MainPage extends StatefulWidget {
  const MainPage({super.key, required this.title});

  final String title;

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  final List<NavbarItem> navbarItems = [];
  final List<Widget> pagers = [];

  @override
  void initState() {
    super.initState();
    initPagers();
    initNavbarItems();
  }

  initPagers() {
    pagers.add(const HomePage());
    pagers.add(RankingPage(text: "榜单", color: Colors.white));
    pagers.add(RankingPage(text: "分类", color: Colors.green));
    pagers.add(RankingPage(text: "我的", color: Colors.pinkAccent));
  }

  initNavbarItems() {
    navbarItems.add(NavbarItem(
        name: '首页',
        icon: '${Constant.ASSETS_IMG}icon_home.png',
        iconChecked: '${Constant.ASSETS_IMG}icon_home.png'));
    navbarItems.add(NavbarItem(
        name: '榜单',
        icon: '${Constant.ASSETS_IMG}icon_rank.png',
        iconChecked: '${Constant.ASSETS_IMG}icon_rank.png'));

    navbarItems.add(NavbarItem(
        name: '分类',
        icon: '${Constant.ASSETS_IMG}icon_search.png',
        iconChecked: '${Constant.ASSETS_IMG}icon_search.png'));

    navbarItems.add(NavbarItem(
        name: '我的',
        icon: '${Constant.ASSETS_IMG}icon_mine.png',
        iconChecked: '${Constant.ASSETS_IMG}icon_mine.png'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: null,
        body: NavigationBarWidget(
          pagers: pagers,
          navbarItems: navbarItems
        )
    );
  }
}
